package com.huawei.appmarket.service.store.awk.card;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.store.bean.detail.DetailResponse.HeadIcon;
import com.huawei.appgallery.foundation.ui.css.CSSDeclaration;
import com.huawei.appgallery.foundation.ui.css.adapter.CSSPropertyName;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSMonoColor;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSValue;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appmarket.framework.widget.ArrowImageView;
import com.huawei.appmarket.framework.widget.CustomActionBar;
import com.huawei.appmarket.framework.widget.RenderFrameLayout;
import com.huawei.appmarket.framework.widget.RenderImageView;
import com.huawei.appmarket.framework.widget.RenderImageView.b;
import com.huawei.appmarket.service.appdetail.view.widget.MultiLineTextView;
import com.huawei.appmarket.service.appdetail.view.widget.MultiLineTextView.e;
import com.huawei.appmarket.service.store.awk.bean.TopImageCardBean;
import o.azb;
import o.cgz;
import o.ContentManager;
import o.epv;
import o.eqx;
import o.eqz;
import o.erq;
import o.ewm.j;
import o.fis;

public class TopImageCard extends BaseDistCard implements e, b {
    private RenderImageView ʻ;
    private MultiLineTextView ʼ;
    private boolean ʽ = false;
    private RenderFrameLayout ˋ;
    private Context ॱॱ;
    private ArrowImageView ᐝ;

    public TopImageCard(Context context) {
        super(context);
        this.ॱॱ = context;
    }

    public cgz ˏ(View view) {
        this.ʻ = (RenderImageView) view.findViewById(j.ʼᐧ);
        this.ʼ = (MultiLineTextView) view.findViewById(j.ˋ);
        this.ᐝ = (ArrowImageView) view.findViewById(j.ˎـ);
        this.ˋ = (RenderFrameLayout) view.findViewById(j.ʾˊ);
        this.ˋ.setListener(this);
        ʽ(view);
        ˎ();
        return this;
    }

    private void ˎ() {
        this.ˋ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ TopImageCard ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(View view) {
                this.ˎ.ˊ();
            }
        });
        int ˊ = azb.ˊ(this.ॱॱ);
        this.ˋ.setPadding(ˊ, this.ˋ.getPaddingTop(), ˊ, this.ˋ.getPaddingBottom());
        this.ʼ.setMaxLine(1);
        this.ʼ.setOnContentChangedListener(this);
        this.ʼ.setResize(true);
    }

    private void ˊ() {
        if (this.ʽ) {
            this.ʽ = false;
            this.ᐝ.setArrowUp(false);
        } else {
            this.ʽ = true;
            this.ᐝ.setArrowUp(true);
        }
        this.ʼ.ˎ();
    }

    public void ˊ(boolean z) {
        if (z) {
            this.ᐝ.setVisibility(0);
        } else {
            this.ᐝ.setVisibility(8);
        }
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof TopImageCardBean) {
            TopImageCardBean topImageCardBean = (TopImageCardBean) cardBean;
            if (topImageCardBean.ˊ() != null) {
                ॱ(topImageCardBean.ˊ());
            } else {
                this.ʻ.setVisibility(8);
            }
            if (topImageCardBean.ॱ() != null) {
                ˊ(topImageCardBean.ॱ());
            } else {
                this.ˋ.setVisibility(8);
            }
        }
    }

    private void ॱ(HeadIcon headIcon) {
        this.ʻ.setVisibility(0);
        LayoutParams layoutParams = this.ʻ.getLayoutParams();
        if (layoutParams != null) {
            int i = this.ʼॱ.getResources().getConfiguration().orientation;
            if (1 == i) {
                ˎ(headIcon.ˊ());
                layoutParams.height = (int) (((float) epv.ˊ(fis.ˎ())) * 0.5625f);
            } else if (2 == i) {
                ˎ(headIcon.ॱ());
                layoutParams.height = epv.ˊ(fis.ˎ()) / 3;
            }
            this.ʻ.setLayoutParams(layoutParams);
        }
    }

    private void ˊ(String str) {
        this.ˋ.setVisibility(0);
        if (this.ʽ) {
            this.ᐝ.setArrowUp(true);
        } else {
            this.ᐝ.setArrowUp(false);
        }
        if (this.ʼ.ˏ() != null && !this.ʽ) {
            this.ʼ.setSimpleContent(this.ʼ.ˏ());
        } else if (this.ʼ.ॱ() == null) {
            this.ʼ.setContent(str);
        } else {
            this.ʼ.setContent(this.ʼ.ॱ());
        }
    }

    public TopImageCardBean ˋ() {
        if (this.ˊᐝ != null) {
            return (TopImageCardBean) this.ˊᐝ;
        }
        return null;
    }

    private void ˎ(String str) {
        eqx.ॱ(fis.ˎ(), str, new eqz(this) {
            final /* synthetic */ TopImageCard ˋ;

            {
                this.ˋ = r1;
            }

            public void ॱ(Bitmap bitmap) {
                if (bitmap != null) {
                    this.ˋ.ʻ.setImageDrawable(new BitmapDrawable(ContentManager.getInstant().getContext().getResources(), bitmap));
                    int ˎ = erq.ˎ(bitmap);
                    if (this.ˋ.ˋ().ʽ() != 1) {
                        CustomActionBar.ˎ(this.ˋ.ॱॱ, ˎ, 0);
                    }
                }
            }
        });
    }

    public boolean ˋ(CSSDeclaration cSSDeclaration) {
        CSSValue propertyValue = cSSDeclaration.getPropertyValue(CSSPropertyName.BACKGROUND_COLOR);
        if (propertyValue == null || !(propertyValue instanceof CSSMonoColor)) {
            return false;
        }
        this.ʻ.setRenderColor(((CSSMonoColor) propertyValue).getColor());
        return true;
    }
}
